/**
 * clock.c
 *
 * A GTK+ widget that implements a clock face
 *
 * (c) 2005, Davyd Madeley
 *
 * Authors:
 *   Davyd Madeley  <davyd@madeley.id.au>
 */

#include <gtk/gtk.h>
#include <math.h>

#include "clock.h"

G_DEFINE_TYPE (EggClockFace, egg_clock_face, GTK_TYPE_DRAWING_AREA);

static gboolean egg_clock_face_expose (GtkWidget *clock, GdkEventExpose *event);

static void
egg_clock_face_class_init (EggClockFaceClass *class)
{
	GtkWidgetClass *widget_class;

	widget_class = GTK_WIDGET_CLASS (class);

	widget_class->expose_event = egg_clock_face_expose;
}

static void
egg_clock_face_init (EggClockFace *clock)
{
}

static void
draw (GtkWidget *clock, cairo_t *cr)
{
	double x, y, xx, yy, X;
	double radius;
	int i,j,c;
	
	xx = clock->allocation.width;
	yy = clock->allocation.height;
	x = clock->allocation.x + clock->allocation.width / 2; 
 	y = clock->allocation.y + clock->allocation.height / 2;
 	radius = MIN (clock->allocation.width / 2, 
 		      clock->allocation.height / 2) - 5; 


	cairo_set_source_rgb (cr, 0, 0, 0);

	if ( xx > yy ){
		X = yy/9;
	} else {
		X =xx/9;
	}


	for ( j=1; j<=8; j++){
		if ( j%2 == 0){
			c=0;
		}else{
			c=1;
		}
		for ( i=1; i <=8; i++){
			printf("%d\n",i%2);
			if ( (i+c)%2 == 0){
				cairo_set_source_rgb (cr, 0.9, 0.9, 0.9);
/* 				cairo_stroke (cr); */
				printf("ici\n");
			} else {
				cairo_set_source_rgb (cr, 0.45, 0.45, 0.45);
/* 				cairo_stroke (cr); */
				printf("la\n");
			}
			cairo_rectangle(cr, 5+i*X*0.90, 5+j*X*0.90, X*0.90, X*0.90);
			cairo_fill(cr);
		}
	}
/* 	cairo_stroke (cr); */
	cairo_restore (cr);/*  stack-pen-size */




}

       
static gboolean
egg_clock_face_expose (GtkWidget *clock, GdkEventExpose *event)
{
	cairo_t *cr;

	/* get a cairo_t */
	cr = gdk_cairo_create (clock->window);

	cairo_rectangle (cr,
			event->area.x, event->area.y,
			event->area.width, event->area.height);
	cairo_clip (cr);
	
	draw (clock, cr);

	cairo_destroy (cr);

	return FALSE;
}

GtkWidget *
egg_clock_face_new (void)
{
	return g_object_new (EGG_TYPE_CLOCK_FACE, NULL);
}
